﻿using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YJYpublicClass
{
    public partial class Frm_视觉流程 : Form
    {
        public Frm_视觉流程()
        {
            InitializeComponent();
        }
        //Block//外面传进来的参数
        public   CogToolBlock cogBlockIN = null;

        private void Frm_视觉流程_Load(object sender, EventArgs e)
        {
            this.cogToolBlockEditV21.Subject = cogBlockIN;
            this.txt_VPPpath.Text = 外设.SysPras.Vpppath;
        }

        private void btn_切换流程_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "ALL Image Files|*.VPP";
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string path = openFileDialog1.FileName;
                //写数据
              CogToolBlock tempBlock = CogSerializer.LoadObjectFromFile(path) as CogToolBlock;
              cogBlockIN = tempBlock;
              this.cogToolBlockEditV21.Subject = cogBlockIN;
              this.txt_VPPpath.Text = path;
            //保存路径
              外设.SysPras.Vpppath = path;
              //保存路径
              XmlHelper.SaveXML(SystemPras.SyspPrasFpath, 外设.SysPras);
            }
        }

        private void btn_SaveDown2_Click(object sender, EventArgs e)
        {
            try
            {
                CogSerializer.SaveObjectToFile(cogBlockIN, 外设.SysPras.Vpppath);
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void btn_流程另存_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            try
            {
                saveFileDialog1.Filter = "ALL Image Files|*.VPP";
                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string path = saveFileDialog1.FileName;
                    //写数据
                    CogSerializer.SaveObjectToFile(cogBlockIN, path);
                    //同时更新路径？
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btn_更新标定参数_Click(object sender, EventArgs e)
        {

        }

     
    }
}
